/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketmaster.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.RowSet;
import ticketmaster.dataobject.PremiumCustomer;

/**
 *
 * @author Wei Liu
 */
public class PremiumCustomerDAO extends BaseEntityDAO
{
    public PremiumCustomerDAO()
    {
        // initialization
    }

    /**
     * Insert premiumCustomer into database
     * @param premiumCustomer the new premiumCustomer entity to be inserted
     * @return newly created premiumCustomer number or a 0 on error
     */
    public int insertPremiumCustomer(PremiumCustomer premiumCustomer)
    {
        return save(premiumCustomer);
    }

    /**
     * Delete premiumCustomer that matches the supplied criteria
     * @param premiumCustomer the supplied criteria
     * @return true on success, false on failure
     */
    public boolean deletePremiumCustomer(PremiumCustomer premiumCustomer)
    {
        return delete(premiumCustomer);
    }

    /**
     * Update the premiumCustomer using data from the premiumCustomer Data Object
     * @param premiumCustomer the premiumCustomer Data Object to be updated
     * @return true on success, false on failure or error
     */
    public boolean updatePremiumCustomer(PremiumCustomer premiumCustomer)
    {
        if (premiumCustomer.getPremiumCustomerID() == 0)
        {
            return false;
        }

        if (update(premiumCustomer))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Get the premiumCustomer that matches the supplied criteria
     * @param premiumCustomer the supplied criteria
     * @return a Data Object if found, or null on error or if not found
     */
    public PremiumCustomer findPremiumCustomer(PremiumCustomer premiumCustomer)
    {
        String sql = buildQuerySQL(premiumCustomer);
        RowSet crs = query(sql);
        try
        {
            crs.next();
        }
        catch (SQLException ex)
        {
            Logger.getLogger(PremiumCustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return (PremiumCustomer) this.getObject(crs, premiumCustomer);
    }

    /**
     * Get all premiumCustomers that match the supplied criteria
     * @param premiumCustomer supplied criteria
     * @return a RowSet
     */
    public RowSet getPremiumCustomersRS(PremiumCustomer premiumCustomer)
    {
        String sql = buildQuerySQL(premiumCustomer);
        return query(sql);
    }

    /**
     * Get all premiumCustomers that match the supplied criteria
     * @param premiumCustomer supplied criteria
     * @return a collection of PremiumCustomer Data Objects
     */
    public Collection<PremiumCustomer> getPremiumCustomersDO(PremiumCustomer premiumCustomer)
    {
        String sql = buildQuerySQL(premiumCustomer);

        RowSet crs = query(sql);
        Collection<PremiumCustomer> premiumCustomers = new ArrayList<PremiumCustomer>();
        try
        {
            while (crs.next())
            {
                PremiumCustomer premiumCustomerDO = (PremiumCustomer) this.getObject(crs, premiumCustomer);
                PremiumCustomer item = new PremiumCustomer();
                item.setPremiumCustomerID(premiumCustomerDO.getPremiumCustomerID());
                item.setCustomerID(premiumCustomerDO.getCustomerID());
                item.setRegistrationDate(premiumCustomerDO.getRegistrationDate());
                item.setPoints(premiumCustomerDO.getPoints());
                premiumCustomers.add(item);
            }
        }
        catch (SQLException ex)
        {
            Logger.getLogger(PremiumCustomerDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return premiumCustomers;
    }
}
